home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / network / atre12.zip / LF.ZIP / ATREE.H < prev    next >
Text File  |  1991-07-05  |  9KB  |  172 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** atree.h                                                             ****
  4.  ****                                                                     ****
  5.  **** Copyright (C) A. Dwelly and W.W. Armstrong, 1990.                   ****
  6.  ****                                                                     ****
  7.  **** All rights reserved.                                                ****
  8.  ****                                                                     ****
  9.  **** This is the include file for the "research" version of the adaptive ****
  10.  **** logic network package based on work done by Prof. W. W. Armstrong   ****
  11.  **** and others in the Department of Computing Science, University of    ****
  12.  **** Alberta, and previous work at the Universite de Montreal, and at    ****
  13.  **** AT&T Bell Laboratories, Holmdel, N. J.  The software demonstrates   ****
  14.  **** that networks consisting of many layers of linear threshold         ****
  15.  **** elements can indeed be effectively trained.                         ****
  16.  ****                                                                     ****
  17.  **** License:                                                            ****
  18.  **** A royalty-free license is granted for the use of this software for  ****
  19.  **** NON-COMMERCIAL PURPOSES ONLY. The software may be copied and        ****
  20.  **** modified provided this notice appears in its entirety and unchanged ****
  21.  **** in all copies, whether changed or not.  Persons modifying the code  ****
  22.  **** are requested to state the date, the changes made and who made them ****
  23.  **** in the modification history.                                        ****
  24.  ****                                                                     ****
  25.  **** Warranty:                                                           ****
  26.  **** No warranty of any kind is provided with this software.             ****
  27.  **** This software is not supported.  Neither the authors, nor the       ****
  28.  **** University of Alberta, its officers, agents, servants or employees  ****
  29.  **** shall be liable or responsible in any way for any damage to         ****
  30.  **** property or direct personal or consequential injury of any nature   ****
  31.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  32.  **** or any other party as a consequence of the use or disposition of    ****
  33.  **** this software.                                                      ****
  34.  ****                                                                     ****
  35.  **** Patent:                                                             ****
  36.  **** The use of a digital circuit which transmits a signal indicating    ****
  37.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  38.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  39.  **** W. W. Armstrong, President.                                         ****
  40.  ****                                                                     **** 
  41.  **** A royalty-free license is granted for the use of this patent to     ****
  42.  **** run this software for NON-COMMERCIAL PURPOSES ONLY and the          ****
  43.  **** extension of this patent license to modified versions of this       ****
  44.  **** software is granted provided the purpose is NON-COMMERCIAL ONLY.    ****
  45.  ****                                                                     ****
  46.  **** Modification history:                                               ****
  47.  ****                                                                     ****
  48.  **** 90.09.05 Initial implementation, A.Dwelly                           ****
  49.  **** 91.04.15 Port to PC and minor bug fixes, R. Manderscheid            ****
  50.  **** 91.05.20 Windows Extensions, M. Thomas                              ****
  51.  ****                                                                     ****
  52.  ****                                                                     ****
  53.  **** References:                                                         ****
  54.  ****                                                                     ****
  55.  **** For technical details see "Experiments using Parsimonious Adaptive  ****
  56.  **** Logic" W. W. Armstrong, Jiandong Liang, Dekang Lin, Scott Reynolds  ****
  57.  **** Tech. Rept. TR 90-30, Department of Computing Science, University   ****
  58.  **** of Alberta, Edmonton, Alberta, Canada T6G 2H1, September 1990.      ****
  59.  ****                                                                     ****
  60.  **** The adaptive algorithm is described in the article "Adaptation      ****
  61.  **** Algorithms for Binary Tree Networks", by W. W. Armstrong and J.     ****
  62.  **** Gecsei, IEEE Trans. on Systems, Man and Cybernetics,                ****
  63.  **** vol. SMC-9, no. 5 (1979), 276 - 285.  In this C-language "research" ****
  64.  **** version, some recently discovered improvements are used.            ****
  65.  **** This version has been written with clarity, not performance,        ****
  66.  **** in mind.                                                            ****
  67.  ****                                                                     ****
  68.  **** Please contact W. W. Armstrong at the above address at U. of A. in  ****
  69.  **** case of questions or problems.  Tel. (403) 492 2374.                ****
  70.  ****                                                                     ****
  71.  *****************************************************************************/
  72.  
  73.  
  74. /*****************************************************************************
  75.  ****                                                                     ****
  76.  **** atree                                                               ****
  77.  ****                                                                     ****
  78.  **** An atree is the fundamental structure used by these routines; it is ****
  79.  **** a binary tree with nodes taking one of four logical functions, AND, ****
  80.  **** OR, LEFT or RIGHT depending on initialization or the training it    ****
  81.  **** has undergone.  The tree is randomly connected to input variables   ****
  82.  **** and their complements.                                              ****
  83.  ****                                                                     ****
  84.  *****************************************************************************/
  85.  
  86. typedef struct atree_strc
  87. {
  88.     /******************************
  89.     * 16 byte data structure
  90.     * If needed, could squish
  91.     * cmp_flags, but 16 bytes will
  92.     * allow easy alignment within
  93.     * segments
  94.     *******************************/
  95.  
  96.     char leaf_flag;
  97.     char left_cmp_flag;
  98.     char right_cmp_flag;
  99.     char function;
  100.     char sig_left;
  101.     char sig_right;
  102.     char cnt_10;
  103.     char cnt_01;
  104.     union l_dec {
  105.         struct atree_strc far *child;
  106.         int leaf;
  107.     } left;
  108.     union r_dec {
  109.         struct atree_strc far *child;
  110.         int leaf;
  111.     } right;
  112. }
  113. atree;
  114.  
  115. typedef atree far *LPATREE;
  116.  
  117. /*****************************************************************************
  118.  ****                                                                     ****
  119.  **** bit_vec                                                             ****
  120.  ****                                                                     ****
  121.  **** A bit_vec is a packed vector of bits, stored in an array of chars.  ****
  122.  *****************************************************************************/
  123.  
  124. typedef struct bit_vec_strc
  125. {
  126.     int len;    /* The length of the vector in bits */
  127.     LPSTR bv;
  128. }
  129. bit_vec;
  130.  
  131. typedef bit_vec far *LPBIT_VEC;
  132.  
  133. /* Import public routines */
  134.  
  135. void FAR PASCAL         Windows_Interrupt(DWORD);
  136. LPATREE FAR PASCAL      atree_create(int, int);
  137. void FAR PASCAL         atree_init(void);
  138. void FAR PASCAL         atree_print(LPATREE, int);
  139. int  FAR PASCAL         atree_size();
  140. LPATREE FAR PASCAL      atree_load();
  141. int  FAR PASCAL         atree_store();
  142. int  FAR PASCAL         atree_eval(LPATREE, LPBIT_VEC);
  143. int  FAR PASCAL         atree_train(LPATREE, LPBIT_VEC, LPBIT_VEC,int,int,int,int,int);
  144. LPBIT_VEC FAR PASCAL    atree_rand_walk(int, int, int);
  145.  
  146. int  FAR PASCAL         bv_diff(LPBIT_VEC, LPBIT_VEC);
  147. LPBIT_VEC FAR PASCAL    bv_create(int);
  148. LPBIT_VEC FAR PASCAL    bv_pack(LPSTR, int);
  149. LPBIT_VEC FAR PASCAL    bv_concat(int, LPBIT_VEC FAR *);
  150. LPBIT_VEC FAR PASCAL    bv_copy(LPBIT_VEC);
  151. void FAR PASCAL         bv_set(int,LPBIT_VEC,int);
  152. int  FAR PASCAL         bv_extract(int,LPBIT_VEC);
  153. int  FAR PASCAL         bv_equal(LPBIT_VEC, LPBIT_VEC);
  154. void FAR PASCAL         bv_free(LPBIT_VEC);
  155. void FAR PASCAL         bv_print(FILE *, LPBIT_VEC);
  156.  
  157. LPSTR FAR PASCAL        WinMem_Malloc(WORD, WORD);
  158. LPSTR FAR PASCAL        WinMem_Free(LPSTR);
  159.  
  160. /* some public Macros */
  161.  
  162. #define MEMCHECK(p) \
  163.         if (p == NULL){ \
  164.                        char szBuffer[30]; \
  165.                        wsprintf(szBuffer,"%s, line %d ",  __FILE__, __LINE__);\
  166.                        MessageBox(NULL,szBuffer,"Out of Memory",MB_OK | MB_ICONSTOP);\
  167.                        exit(0);\
  168.                       }
  169.  
  170. #define bcopy(src,dest,len) memcpy(dest,src,len)
  171. #define RANDOM(b) (rand() % (b))
  172.